﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Script.Services;
using System.Web.Services;
using Adex;
using MediaMonitor.Common;

namespace MediaMonitor.Controls
{

    public partial class AutoCompleteExtender : System.Web.UI.UserControl
    {

        public string BehaviorID
        {
            get { return this.AutoComplete.BehaviorID; }
            set { this.AutoComplete.BehaviorID = value; }
        }

        public string ContextKey
        {
            get { return this.AutoComplete.ContextKey; }
            set { this.AutoComplete.ContextKey = value; }
        }

        public string ServicePath
        {

            get { return AutoComplete.ServicePath; }
            set
            {
                AutoComplete.ServicePath = value;
            }
        }

        public string ScriptPath
        {

            get { return AutoComplete.ScriptPath; }
            set
            {
                AutoComplete.ScriptPath = value;
            }
        }


        public string ServiceMethod
        {

            get { return AutoComplete.ServiceMethod; }
            set
            {
                AutoComplete.ServiceMethod = value;
            }
        }

        public int MinimumPrefixLength
        {
            get { return AutoComplete.MinimumPrefixLength; }
            set { AutoComplete.MinimumPrefixLength = value; }
        }

        public int ResultSetCount
        {
            get { return AutoComplete.CompletionSetCount; }
            set { AutoComplete.CompletionSetCount = ResultSetCount; }
        }


        public string SelectedValue
        {
            get { return hdnSelectedValue.Value; }
            set
            {
                hdnSelectedValue.Value = value;
            }
        }

        protected void Page_Init(object sender, EventArgs e)
        {
            ////if(!(this.Page.IsPostBack)){
            //    string script = "";
            //    script += " function ItemSelected_" + this.ClientID + "(source, eventArgs) { ";
            //    script += "      document.getElementById('" + hdnAutoComplete.ClientID + "').value = eventArgs.get_value();";
            //    script += " }";
            //    ScriptManager.RegisterClientScriptBlock(this.Page, System.Type.GetType("System.String"),
            //                                            new Random().NextDouble().ToString(), script, true);
            ////}
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!(this.Page.IsPostBack))
            {
                BehaviorID = "AutoCompleteEx_" + this.ID;

                //this.AutoComplete.CompletionListElementID = "divAutoComplete_" + this.ID;

                this.AutoComplete.OnClientItemSelected = "ItemSelected_" + this.ID;

                this.tbAutoComplete.Attributes.Add("onkeyup", "javascript: Unselected_" + this.ID + "();");
                this.tbAutoComplete.Attributes.Add("onload", "javascript: Load_" + this.ID + "();");

            }
            else
            {
                //do nothing;
                //this.SelectedValue = Request[this.hdnSelectedValue.ClientID];
            }


           

        }




    }

}